﻿using Microsoft.AspNetCore.SignalR;
using System.Security.Claims;

namespace Ebusiness_OrderService.Services
{
    public class ChatRoomHub : Hub
    {
        public ChatRoomHub() 
        {
        
        }

        //公共发送消息
        public Task SendPublicMessage(string message)
        {
            //var userId = Context.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value;
            string connld = this.Context.ConnectionId;
            string msg = $"{connld} {DateTime.Now}:{message}";
            //this.Clients.Caller; // 自己
            //this.Clients.Group("dev"); 组
            //this.Clients.Others; //其他人
            //this.Clients.OthersInGroup(""); //组中其他人 不包含自己
            //this.Clients.User("");
            //this.Clients.Users();
            //this.Groups.AddToGroupAsync("", "");
            return Clients.All.SendAsync("ReceivePublicMessage", msg, "123");
        }
    }
}
